<template>
	<div>
		<div class="container">
			<div class="form-box">
				<el-form ref="form" :model="form" label-width="80px">
					<el-form-item label="旧密码">
						<el-input type="password" v-model="form.password"></el-input>
					</el-form-item>
					<el-form-item label="新密码">
						<el-input type="password" v-model="form.newPassword"></el-input>
					</el-form-item>
					<el-form-item label="确认密码">
						<el-input type="password" v-model="form.ComfirmPwd"></el-input>
					</el-form-item>
					<el-form-item>
						<el-button type="buttton" @click="onSubmit">保存</el-button>
					</el-form-item>
				</el-form>
			</div>
		</div>
	</div>
</template>

<script>
	import Vue from 'vue';
	import $ from 'jquery';
	import md5 from 'js-md5';
	let Base64 = require('js-base64').Base64;
	export default {
		data: function() {
			return {
				form: {
					userCount: '',
					password: '',
					newPassword: '',
					ComfirmPwd: ''
				}
			}
		},
		methods: {
			onSubmit() {
				let self = this;
				if(this.form.password == '') {
					this.$message("旧密码不能为空！");
					return false;
				} else if(this.form.newPassword == '') {
					this.$message("新密码不能为空！");
					return false;
				} else if(this.form.ComfirmPwd == '') {
					this.$message("确认密码不能为空！");
					return false;
				} else if(this.form.ComfirmPwd != this.form.newPassword) {
					this.$message("两次输入的新密码不一致！");
					return false;
				}
				let param = {};
//				param.password = Base64.encode(md5(this.form.password));
//				param.newPassword = Base64.encode(md5(this.form.newPassword));
				param.userCount = sessionStorage.getItem('userCount');
				param.password = this.form.password;
				param.newPassword = this.form.newPassword;
				this.httptool.ajaxPost("user/savepassword", param, function(res) {
					if(res.code==1) {
						self.$message.success('提交成功！');
						sessionStorage.removeItem('token');
						sessionStorage.removeItem('userName');
						setTimeout(function() {
							self.$router.push('/login');
						}, 2000);
					}
				});

			}
		}
	}
</script>